package org.junv;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/EquipList")
public class EquipList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String sql="select a.equipId,a.equipName,a.equipCount,a.equipDescr,b.equipBorrAble,b.equipBorrTime,b.equipBorrPlace,c.equipCategoryId"+
                   " from equipInfo a,equipBorrAble b,equipToCate c"+
                    " where a.equipId=b.equipId and a.equipId= c.equipId"+
                    "   order by a.equipId;";
		
		
		
		ResultSet rs=null;
		DBBean myBean = new DBBean();
		myBean.init();
		rs=myBean.executeQuery(sql);
		
		try {
			if(rs.next()){
				out.println("<table  border='1'>");
				out.println("<tr><th>器材ID</th><th>器材名称</th><th>器材数量    </th><th>器材描述</th><th>是否可借</th><th>可借时间</th><th>借用地点</th><th>器材类别ID</th><th>删除</th></tr>");
				while(rs.next()){
					out.println("<tr><td>"+rs.getString("equipId")+"</td><td>"+rs.getString("equipName")+
						"</td><td>"+rs.getString("equipCount")+"</td><td>"+rs.getString("equipDescr")+"</td><td>"+
						rs.getString("equipBorrAble")+"</td><td>"+rs.getString("equipBorrTime")+"</td><td>"+
						rs.getString("equipBorrPlace")+"</td><td>"+rs.getString("equipCategoryId")+"</td><td>"+
						"<a href='DelEquip?equipId="+rs.getString("equipId")+"'>删除</a>"+"</td></tr>");
					
					
				}
				out.println("</table>");
			}else{
				out.print("没有可以显示的内容");
				return;
			}
		} catch (SQLException e) {
			
			System.out.println("Result这里出了问题。。。。");
			e.printStackTrace();
			myBean.colse();
		}
		myBean.colse();	
	}

	
}
